import os

# 需要在数据序列上执行聚合函数，但是首先需要先转换或者过滤数据
def demo_1():
    nums = [1,2,3,4,5]
    s = sum(x * x for x in nums)
    print(s)

def demo_2():
    portfolio = [
        {'name': 'goog', 'shares': 50},
        {'name': 'yhoo', 'shares': 75},
        {'name': 'aol', 'shares': 20},
        {'name': 'scox', 'shares': 65},
    ]
    min_shares = min(s['shares'] for s in portfolio)
    print(min_shares)

    # 使用lambda可以节省内存
    min_shares_lambda = min(portfolio, key=lambda a : a['shares'])
    print(min_shares_lambda)

if __name__ == '__main__':
    # demo_1()
    demo_2()